package com.xinhe.web.controller;

import com.querydsl.core.QueryResults;
import com.xinhe.web.annotation.WebUsed;
import com.xinhe.web.common.Result;
import com.xinhe.web.entity.Coupon;
import com.xinhe.web.service.CouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Date;

@Api(value = "优惠劵", tags = {"优惠劵"})
@RestController
@RequestMapping(value = {"/coupon"}, produces = {"application/json;charset=UTF-8"})

public class CouponController {
    @Autowired
    private CouponService couponService;

    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "分页查询优惠劵")
    @RequestMapping({"/pageCoupon"})
    public QueryResults<Coupon> pageCoupon(String name, int pageNum, int pageSize) {
        return this.couponService.pageCoupon(name,pageNum,pageSize);
    }
    @WebUsed
    @ApiOperation(httpMethod = "POST", value = "保存优惠劵")
    @RequestMapping({"/saveCoupon"})
    public Result saveCoupon(Long id,String name, Date expireTime, BigDecimal money,
                             BigDecimal satisfyMoney,String type,String remark) {
        return this.couponService.saveCoupon(id,name,expireTime,money,satisfyMoney,type,remark);
    }
    @WebUsed
    @ApiOperation(httpMethod = "POST", value = "修改优惠劵状态")
    @RequestMapping({"/saveCouponStatus"})
    public Result saveCouponStatus(Long couponId, String status) {
        return this.couponService.saveCouponStatus(couponId, status);
    }
    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "删除优惠劵")
    @ApiImplicitParam(name = "couponId", value = "标识", required = true)
    @RequestMapping({"/deleteCoupon"})
    public Result deleteCoupon(Long couponId) {
        return this.couponService.delete(couponId);
    }

    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "优惠劵详情")
    @ApiImplicitParam(name = "couponId", value = "标识", required = true)
    @RequestMapping({"/detailCoupon"})
    public Result<Coupon> detailCoupon(Long couponId) {
        return this.couponService.findById(couponId);
    }




}
